/*
 * @Author: yx_ning
 * @Description:
 * @File: global
 * @Version: 1.0.0
 * @Date: 20/12/2023 下午4:33
 */
package global

import (
	"gin-simple/config"
	"gin-simple/utils/timer"
	ut "github.com/go-playground/universal-translator"
	"github.com/go-playground/validator/v10"
	"github.com/redis/go-redis/v9"
	"github.com/songzhibin97/gkit/cache/local_cache"
	"github.com/spf13/viper"
	"go.uber.org/zap"
	"golang.org/x/sync/singleflight"
	"gorm.io/gorm"
	"sync"
)

var (
	DB     *gorm.DB
	REDIS  *redis.Client
	VP     *viper.Viper
	LOG    *zap.Logger
	LOCK   sync.RWMutex
	CONFIG config.Config

	BlackCache              local_cache.Cache
	TIMER                   timer.Timer = timer.NewTimerTask()
	DBList                  map[string]*gorm.DB
	GVA_Concurrency_Control = &singleflight.Group{}
	Validate                *validator.Validate
	Trans                   ut.Translator
	lock                    sync.RWMutex
)

// GetGlobalDBByDBName 通过名称获取db list中的db
func GetGlobalDBByDBName(dbname string) *gorm.DB {
	lock.RLock()
	defer lock.RUnlock()
	return DBList[dbname]
}
